package com.zhongkun.datahome.web.rest;

import com.zhongkun.datahome.common.annotation.Log;
import com.zhongkun.datahome.common.core.controller.BaseController;
import com.zhongkun.datahome.common.core.domain.R;
import com.zhongkun.datahome.common.enums.BusinessType;
import com.zhongkun.datahome.service.req.IdBody;
import com.zhongkun.datahome.service.req.cmd.task.TaskCmd;
import com.zhongkun.datahome.service.req.cmd.task.TaskProcessCmd;
import com.zhongkun.datahome.service.req.qry.task.TaskQry;
import com.zhongkun.datahome.service.res.PageVo;
import com.zhongkun.datahome.service.res.task.TaskVo;
import com.zhongkun.datahome.service.service.ITaskService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 任务Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/core/task")
public class TaskController extends BaseController {
    @Resource
    private ITaskService taskService;

    @ApiOperation("分页查询任务列表")
    @GetMapping("/page")
    public R<PageVo<TaskVo>> page(TaskQry qry) {
        return R.ok(taskService.page(qry));
    }

    @ApiOperation("获取任务详细信息")
    @GetMapping(value = "/{id}")
    public R<TaskVo> getInfo(@PathVariable("id") Long id) {
        return R.ok(taskService.getInfo(id));
    }

    @ApiOperation("新增任务")
    @Log(title = "任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Long> add(@RequestBody TaskCmd cmd) {
        return R.ok(taskService.add(cmd));
    }

    @ApiOperation("继续处理任务")
    @Log(title = "任务", businessType = BusinessType.INSERT)
    @PostMapping("/process")
    public R<Long> process(@RequestBody TaskProcessCmd cmd) {
        return R.ok(taskService.process(cmd));
    }

    @ApiOperation("删除任务")
    @Log(title = "任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public R<Void> remove(@RequestBody IdBody idBody) {
        taskService.remove(idBody.getId());
        return R.ok();
    }
}